/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myyong.test.user;

import com.mkyong.config.MongoUtil;
import com.myyong.model.Address;
import com.myyong.model.User;
import java.util.List;
import org.springframework.data.mongodb.core.MongoOperations;

/**
 *
 * @author dell
 */
public class UserSave {

    private MongoOperations mo = MongoUtil.getMongoOperations();

    public void insert(List<User> userList) {
        for (User user : userList) {
            mo.save(user);
        }
    }

    public void sinsert(User user) {
        mo.save(user);
    }

    public static void main(String[] args) {
        UserSave userSave = new UserSave();
        for (int i = 0; i < 100; i++) {
            User user = new User();
            user.setFirstName("czf" + i);
            user.setLastName("czl" + i);
            user.setAge(i);
            Address address = new Address();
            address.setCity("中国"+i);
            address.setLocation("常州"+i);
            user.setAddress(address);
            userSave.sinsert(user);
            System.out.println(i);
        }
    }
}
